package org.pqsoft.pledgecontract.action;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.velocity.VelocityContext;
import org.pqsoft.pledgecontract.service.ContractGeneral;

import com.mframework.annotation.aOperation;
import com.mframework.exception.mException;
import com.mframework.system.AbstractAction;
import com.mframework.system.PageTemplate;
import com.mframework.system.mSGA;

public class ContractGeneralAction extends AbstractAction {
	private final static String VM_PATH = "pledgecontract/";
	ContractGeneral service = new ContractGeneral();

	/**
	 * 获取页面参数
	 * 
	 * @return
	 */
	private HashMap<String, Object> getParameters1() {
		HashMap<String, Object> m = new HashMap<String, Object>();
		Enumeration<?> en = request.getParameterNames();
		while (en.hasMoreElements()) {
			Object men = en.nextElement();
			m.put(men.toString(), request.getParameter(men.toString()).trim());
		}

		return m;
	}

	public String GeneralManagement() throws mException {
		String str = mSGA.mergeVelocity(VM_PATH + "generalManagement.vm", null);
		return str;
	}

	@aOperation(name = "管理页显示")
	public String list() throws Exception {
		Map<String, Object> param = this.getParameters1();
//		GeneralService service = new GeneralService();
		PageTemplate pageTemplate = service.list(param);
		VelocityContext context = new VelocityContext();
		context.put("param", param);
		context.put("pageTemplate", pageTemplate);
		String str = mSGA.mergeVelocity(VM_PATH + param.get("VM"), context);
		return str;
	}

	@aOperation(name = "查看详细")
	public String BuyPledgesel() throws Exception {
		Map<String, Object> parama = this.getParameters1();
		Map<String, Object> map = (Map<String, Object>) service.select(parama);
		List<Map<String, Object>> list = service.select1(parama);
		VelocityContext context = new VelocityContext();
		System.out.println(map);
		context.put("map", map);
		context.put("map1", list);
		String str = mSGA.mergeVelocity(VM_PATH + parama.get("VM"), context);
		return str;
	}

	@aOperation(name = "添加表单显示")
	public String insertselect() throws Exception {
		Map<String, Object> parama = this.getParameters1();
		Map<String, Object> map = parama;
		VelocityContext context = new VelocityContext();
//		map.put("code", CRMIConstants.businessCode(parama.get("CONTRACT_ID").toString()));
		context.put("map", map);
		String str = mSGA.mergeVelocity(VM_PATH + parama.get("VM"), context);
		return str;
	}

	@aOperation(name = "添加方法")
	public int buyPledgeins() throws Exception {
		Map<String, Object> parama = this.getParameters1();
		int a = service.insert(parama);
		return a;
	}

	@aOperation(name = "更新表单显示")
	public String updateselect() throws Exception {
		Map<String, Object> parama = this.getParameters1();
		Map<String, Object> map = (Map<String, Object>) service.select(parama);
		List<Map<String, Object>> list = service.select1(parama);
		VelocityContext context = new VelocityContext();
		context.put("map", map);
		context.put("map1", list);
		String str = mSGA.mergeVelocity(VM_PATH + parama.get("VM"), context);
		return str;
	}

	@aOperation(name = "更新方法")
	public int PledgeContractupd() throws Exception {
		Map<String, Object> parama = this.getParameters1();
		int a = service.update(parama);
		return a;
	}
}